package leetcode.weekly.week291;

import java.util.HashMap;
import java.util.Map;

import leetcode.IDebug;

public class Solution2 implements IDebug {

	public int minimumCardPickup(int[] cards) {
		Map<Integer, Integer> hash = new HashMap<>();
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < cards.length; i++) {
			int cur = cards[i];
			if (hash.containsKey(cur)) {
				int dif = i - hash.get(cur);
				if (dif < min) {
					min = dif;
				}
			}
			hash.put(cur, i);
		}
		return min == Integer.MAX_VALUE ? -1 : min + 1;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution2 so = new Solution2();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
